﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Pigs.Enemies
{
    class SteelPig : pigs.Pig
    {

        public SteelPig(Texture2D texture, Vector2 playerPosition)
            : base(texture, playerPosition)
        {
            START_SPEED = 0.75f;

            this.shouldEatSlop = false;
            this.ID = "steel";
            this.speed = START_SPEED;
            this.isInvincible = true;
            this.lead = false;
            this.buff = false;
            this.escaped = false;
        }

        // Commented out because push back doesn't work when shot from behind
        // If a steel pig is hit by a bullet, it is pushed back by its current speed
        public override void pushBack()
        {
            //position.X += speed;
            //rectangle = new Rectangle((int)position.X, (int)position.Y, Width, Height);
        }

        //If there is going to be steel pig AI it needs to be implemented here
        public void doAI( List<pigs.Scenery> obstacles, int playerY)
        {
            // If a steel pig recieves a leader buff, double its x speed and make it chase the player
            if (this.lead && !this.buff)
            {
                this.speed *= 2;
                this.buff = true;
            }
            if (this.buff)
            {
                float yTogo = playerY - position.Y;

                if (yTogo > 70) { yTogo = 70; }
                else if (yTogo < -70) { yTogo = -70; }

                if(yTogo > 0)
                {
                    if(this.ObstacleMove(obstacles, "down", this.position).Equals("none"))
                    {
                        this.position.Y += yTogo / 100;
                    }
                }
                else if (yTogo < 0)
                {
                    if (this.ObstacleMove(obstacles, "up", this.position).Equals("none"))
                    {
                        this.position.Y += yTogo / 100;
                    }
                }
                

                rectangle = new Rectangle((int)position.X, (int)position.Y, Width, Height);
            }
            position.X -= speed;
        }

        /// <summary>
        /// The current update method for the steel pig, just makes sure its goign the start speed, moves it and resets its rectangle
        /// </summary>
        /// <param name="gameTime"> the current game time
        public override void steelUpdate(GameTime gameTime, List<pigs.Scenery> obstacles, int playerY)
        {
            if (this.shouldGhost && this.color.A > 70)
            {
                this.color.A--;
                this.color.A--;
                this.color.A--;
            }


            // Standard scenery avoidance
            if (!this.avoidScenery(obstacles))
            {
                this.doAI(obstacles, playerY);
            }
            rectangle = new Rectangle((int)position.X, (int)position.Y, Width, Height);
        }
    }
}
